var mobId, mob, stats;
var 清怪 = true;
var 刷新地图 = true;
var 复活次数 = 11;
var 副本名称 = "组队任务_玩具城101层";
var BOSS_1_id = 9300012;
var BOSS_1_血量倍率 = 60;
var 副本时限 = 1000 * 60 * 60;
var 实例地图 = [922010100, 922010200, 922010300, 922010400, 922010401, 922010402, 922010403, 922010404, 922010405, 922010500, 922010501, 922010502, 922010503, 922010504, 922010505, 922010506, 922010600, 922010700, 922010800, 922010900, 922011000];
var 准备地图 = 922011100;
var 退场倒计时 = 40;
var stg6_combo = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];

function init() {}

function setup(a, d) {
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    var j = em.newInstance(副本名称);
    for (var e = 0; e < 实例地图.length; e++) {
        var c = j.setInstanceMap(实例地图[e]);
        c.resetPQ(a);
        c.resetFully();
        c.killAllMonsters(清怪);
        c.respawn(刷新地图)
    }
    j.startEventTimer(副本时限);
    j.setProperty("FBtime", 副本时限);
    j.setProperty("FBname", 副本名称);
    j.setProperty("strMap", 准备地图);
    var f = em.getMonster(BOSS_1_id).getMobMaxHp() * BOSS_1_血量倍率;
    j.setProperty("BOSShp", f);
    j.getMapInstance(922010200).getPortal("next00").setScriptName("922010200_out");
    j.getMapInstance(922010300).getPortal("next00").setScriptName("922010300_out");
    j.getMapInstance(922010500).getPortal("next00").setScriptName("922010500_out");
    j.getMapInstance(922010700).getPortal("next00").setScriptName("922010700_out");
    j.getMapInstance(922010800).getPortal("next00").setScriptName("922010800_out");
    mobId = BOSS_1_id;
    mob = em.getMonster(mobId);
    mob.setOverrideStats();
    mob.getChangedStats().hp = f;
    mob.getChangedStats().mp = 99000000;
    mob.setSize(300);
    mob.heal();
    j.registerMonster(mob);
    var g = j.getMapInstance(实例地图[19]);
    g.spawnMonsterOnGroundBelow(mob, new java.awt.Point(905, 184));
    for (var m = 0; m < stg6_combo.length; m++) {
        for (var l = 0; l < 3; l++) {
            em.setProperty("stage6_" + stg6_combo[m] + "" + l + "", "0")
        }
    }
    for (var m = 0; m < stg6_combo.length; m++) {
        var o = false;
        while (!o) {
            for (var n = 0; n < 3; n++) {
                if (!o) {
                    var k = false;
                    for (var h = 0; h < 3; h++) {
                        if (em.getProperty("stage6_" + stg6_combo[m] + "" + (h) + "") == null) {
                            em.setProperty("stage6_" + stg6_combo[m] + "" + (h) + "", "0")
                        } else {
                            if (em.getProperty("stage6_" + stg6_combo[m] + "" + (h) + "").equals("1")) {
                                k = true;
                                break
                            }
                        }
                    }
                    if (!k && java.lang.Math.random() < 0.33) {
                        em.setProperty("stage6_" + stg6_combo[m] + "" + (n) + "", "1");
                        o = true;
                        break
                    }
                }
            }
        }
    }
    return j
}

function onItemPickedUp(h, j, i) {
    var c = p.getMapId();
    var d = 0;
    var b = 0;
    var f = "";
    switch (c) {
        case 922010100:
            f = "废弃的塔<第1阶段>";
            d = 20;
            b = 922010200;
            break;
        case 922010200:
            f = "废弃的塔<第2阶段>";
            d = 10;
            b = 922010300;
            break;
        case 922010300:
            f = "废弃的塔<第3阶段>";
            d = 32;
            b = 922010400;
            break;
        case 922010400:
            f = "暗黑塔<外围>";
            d = 14;
            b = 922010500;
            break;
        case 922010401:
            f = "暗黑塔<1>";
            d = 14;
            b = 922010500;
            break;
        case 922010402:
            f = "暗黑塔<2>";
            d = 14;
            b = 922010500;
            break;
        case 922010403:
            f = "暗黑塔<3>";
            d = 14;
            b = 922010500;
            break;
        case 922010404:
            f = "暗黑塔<4>";
            d = 14;
            b = 922010500;
            break;
        case 922010405:
            f = "暗黑塔<5>";
            d = 14;
            b = 922010500;
            break;
        case 922010500:
            f = "塔的迷路<外围>";
            d = 24;
            b = 922010600;
            break;
        case 922010501:
            f = "塔的迷路<1>";
            d = 24;
            b = 922010600;
            break;
        case 922010502:
            f = "塔的迷路<2>";
            d = 24;
            b = 922010600;
            break;
        case 922010503:
            f = "塔的迷路<3>";
            d = 24;
            b = 922010600;
            break;
        case 922010504:
            f = "塔的迷路<4>";
            d = 24;
            b = 922010600;
            break;
        case 922010505:
            f = "塔的迷路<5>";
            d = 24;
            b = 922010600;
            break;
        case 922010506:
            f = "塔的迷路<6>";
            d = 24;
            b = 922010600;
            break;
        case 922010700:
            d = 4;
            b = 922010800;
            break;
        case 922010900:
            d = 1;
            b = 922011000;
            break;
        case 922011000:
            break;
        case 922011100:
            break;
        default:
            break
    }
    if (d > 0) {
        if (i == 4001022) {
            var e = 0;
            h.getPlayers().forEach(function (l) {
                e += l.getAPI().getItemQuantity(4001022)
            });
            var k = d - e;
            var g = j.getAPI().getJobName(j.getAPI().getJob());
            var a = j.getName();
            h.getPlayers().forEach(function (l) {
                if (e >= d) {
                    l.getAPI().fieldEffect_ScreenMsg("quest/party/clear");
                    l.getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100);
                    l.getAPI().fieldEffect_SetObjectState(100, "gate");
                    l.getAPI().removeAll(4001022);
                    l.getAPI().playerMessage(-1, "通往下一关的传送口打开了。");
                    WarpTask(b)
                } else {
                    l.getAPI().getTopMsgFont("" + g + "<" + a + ">在『" + f + "』找到第" + (e) + "枚通行证。", 3, 20, 13, 0);
                    l.getAPI().showMapEffect(true, 5120018, "还差" + k + "枚通关。", 15, false)
                }
            })
        }
        if (i == 4001023) {
            if (c == 922010900) {
                var e = 0;
                h.getPlayers().forEach(function (l) {
                    e += l.getAPI().getItemQuantity(4001023)
                });
                h.getPlayers().forEach(function (l) {
                    if (e >= d) {
                        l.getAPI().fieldEffect_ScreenMsg("quest/party/clear");
                        l.getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100);
                        l.getAPI().fieldEffect_SetObjectState(100, "gate");
                        l.getAPI().removeAll(4001023);
                        l.getAPI().playerMessage(-1, "通往下一关的传送口打开了。");
                        WarpTask(b)
                    } else {
                        l.dropMessage(-1, "搜集到了" + (e) + "个次元的钥匙。")
                    }
                })
            }
        }
    }
}

function WarpTask(a) {
    eim.getPlayers().forEach(function (b) {
        b.scheduleWarpTask(4, a, 0, false)
    })
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(实例地图[0]);
    a.dropMessage(6, "[" + 副本名称 + "] 进入到了挑战地图，请小心行事。");
    a.changeMap(c, c.getPortal(0));
    a.setReviveCount(复活次数);
    a.getAPI().setNumberForQuestInfo(准备地图, "damage", 0)
}

function onPlayerKilled(b, a) {}

function onPlayerRevived(b, a) {
    if (a.getReviveCount() > 0) {
        return true
    } else {
        var c = b.getMapFactoryMap(准备地图);
        a.changeMap(c, c.getPortal(0));
        return true
    }
}

function onMapChanged(d, c, b) {
    var a = 实例地图.indexOf(b);
    if (a < 0) {
        on玩家退场(d, c, false);
        return
    }
    switch (a) {
        case 0:
            break;
        case 1:
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            break;
        case 5:
            break;
        case 6:
            break;
        case 7:
            break;
        case 8:
            break;
        case 9:
            var e = d.getMapInstance(实例地图[9]);
            e.killAllMonsters(清怪);
            青积木怪王(9, 180, 25, 58);
            青积木怪王(9, 180, 125, 58);
            青积木怪王(9, 180, 225, 58);
            break;
        case 10:
            var e = d.getMapInstance(实例地图[9]);
            e.killAllMonsters(清怪);
            青积木怪王(9, 30, -125, -2241);
            青积木怪王(9, 30, -11, -2241);
            青积木怪王(9, 30, 139, -2241);
            青积木怪王(9, 30, -125, -2023);
            青积木怪王(9, 30, -11, -2023);
            青积木怪王(9, 30, 139, -2023);
            青积木怪王(9, 30, -125, -1805);
            青积木怪王(9, 30, -11, -1805);
            青积木怪王(9, 30, 139, -1805);
            break;
        case 11:
            var e = d.getMapInstance(实例地图[11]);
            e.killAllMonsters(清怪);
            圆形刀刃(11, 100, -222, -1493);
            break;
        case 12:
            var e = d.getMapInstance(实例地图[11]);
            e.killAllMonsters(清怪);
            圆形刀刃(11, 100, -222, -1493);
            break;
        case 13:
            var e = d.getMapInstance(实例地图[11]);
            e.killAllMonsters(清怪);
            圆形刀刃(11, 100, -222, -1493);
            break;
        case 14:
            var e = d.getMapInstance(实例地图[11]);
            e.killAllMonsters(清怪);
            圆形刀刃(11, 100, -222, -1493);
            break;
        case 15:
            var e = d.getMapInstance(实例地图[15]);
            e.killAllMonsters(清怪);
            青积木怪王(15, 150, -115, -430);
            青积木怪王(15, 150, -29, -430);
            青积木怪王(15, 150, 94, -430);
            青积木怪王(15, 20, 10, -849);
            青积木怪王(15, 12, -84, -1064);
            青积木怪王(15, 150, 78, -1257);
            青积木怪王(15, 150, -78, -1257);
            超级门锁(15, 500, -7, -2490);
            break;
        case 16:
            break;
        case 17:
            break;
        case 18:
            break;
        case 19:
            break;
        case 20:
            d.startEventTimer(退场倒计时 * 1000);
            break;
        default:
            break
    }
}

function 青积木怪王(c, b, a, e) {
    var d = eim.getMapInstance(实例地图[c]);
    mobId = 9300013;
    mob = em.getMonster(mobId);
    mob.setOverrideStats();
    mob.getChangedStats().hp = 99999999999999;
    mob.setSize(b);
    mob.getChangedStats().matk = 9999999;
    mob.getChangedStats().watk = 9999999;
    mob.getChangedStats().acc = 9999999;
    mob.getChangedStats().level = 9999;
    mob.heal();
    eim.registerMonster(mob);
    d.spawnMonsterOnGroundBelow(mob, new java.awt.Point(a, e))
}

function 超级门锁(c, b, a, e) {
    var d = eim.getMapInstance(实例地图[c]);
    mobId = 9300390;
    mob = em.getMonster(mobId);
    mob.setOverrideStats();
    mob.getChangedStats().hp = 99999999999999;
    mob.setSize(b);
    mob.getChangedStats().matk = 9999999;
    mob.getChangedStats().watk = 9999999;
    mob.getChangedStats().acc = 9999999;
    mob.getChangedStats().level = 9999;
    mob.heal();
    eim.registerMonster(mob);
    d.spawnMonsterOnGroundBelow(mob, new java.awt.Point(a, e))
}

function 圆形刀刃(c, b, a, e) {
    var d = eim.getMapInstance(实例地图[c]);
    mobId = 9300949;
    mob = em.getMonster(mobId);
    mob.setOverrideStats();
    mob.getChangedStats().hp = 99999999999999;
    mob.setSize(b);
    mob.getChangedStats().acc = 9999999;
    mob.getChangedStats().level = 9999;
    mob.heal();
    eim.registerMonster(mob);
    d.spawnMonsterOnGroundBelow(mob, new java.awt.Point(a, e))
}

function onMonsterKilled(b, c) {
    switch (c) {
        case BOSS_1_id:
            openNpc(b, 9130027, "评价系统");
            for (var a = 0; a < b.getPlayerCount(); a++) {
                b.getPlayers().get(a).dropMessage(6, "[" + 副本名称 + "] 成功击杀BOSS！")
            }
            break
    }
    return 1
}

function onMonsterDamaged(b, a, d, e, c) {
    if (d == BOSS_1_id) {
        a.getAPI().addNumberForQuestInfo(准备地图, "damage", e)
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function initPropArrayRandom(a, d, j, b, h) {
    var g = new Array();
    var k = h - b + 1;
    var c = (j - d) < (h - b) ? true : false;
    do {
        var f = randomNum(d, j);
        if (c || g.indexOf(f) < 0) {
            g.push(f);
            k--
        }
    } while (k);
    for (var e = b; e <= h; e++) {
        if (em.getProperty(a + "_" + e) == null) {
            em.setProperty(a + "_" + e, g[e - 1])
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onPartyDisbanded(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, true);
    return 0
};